package com.cheetah.start.auth.power;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.cheetah.start.system.role.service.SysRoleAdminService;
import com.cheetah.start.system.role.service.SysRoleMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 权限 角色
 *
 * @author Feel
 * @date 2021/10/17
 */
@Slf4j
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private SysRoleMenuService roleMenuService;
    @Autowired
    private SysRoleAdminService roleAdminService;

    /**
     * 获得权限列表
     *
     * @param o o
     * @param s
     * @return {@link List<String>}
     */
    @Override
    public List<String> getPermissionList(Object o, String s) {
        int userId = StpUtil.getLoginIdAsInt();
        return roleMenuService.getPermissionByAdminId(userId);
    }

    /**
     * 获取角色列表
     *
     * @param o o
     * @param s
     * @return {@link List<String>}
     */
    @Override
    public List<String> getRoleList(Object o, String s) {
        int userId = StpUtil.getLoginIdAsInt();
        return roleAdminService.getRoleCodeByAdminId(userId);
    }
}
